package com.hcbd.tdwt.ui.setting.hlct;

import android.annotation.SuppressLint;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;


import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.BaseActivity;
import com.hcbd.tdwt.base.BeidouBoxParams;
import com.pangu.bdsdk2021.entity.extensionterminal.DmSxxInfo;
import com.pangu.bdsdk2021.terminal.TerminalSendManager;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@SuppressLint("NonConstantResourceId")
@EActivity(R.layout.activity_box_mode_hlct)
public class BoxModeActivity extends BaseActivity {
    @ViewById
    TextView title;
    @ViewById
    ImageButton headLeft;
    @ViewById
    RelativeLayout topRL;
    @ViewById
    RadioButton normalModeRb,sosRb,trackingModeRb;
    @ViewById
    RadioGroup modeRg;
    @AfterViews
    protected void init() {
        initMsgRegister();
        title.setText("模式设置");
        title.setTextColor(ContextCompat.getColor(this,R.color.black));
        headLeft.setBackground(ContextCompat.getDrawable(this,R.drawable.left_arrow));
        topRL.setBackground(ContextCompat.getDrawable(this,R.color.white));
        setAndroidNativeLightStatusBar(true);
        if(BeidouBoxParams.isBoxConnectNormal){
            showLoading("加载中");
            TerminalSendManager.getInstance().sendFcxMs(0,0);
        }else{
            toast("未连接蓝牙,无法使用该功能!");
        }
    }
    @Click
    void saveBtn(){
        RadioButton radioButton=findViewById(modeRg.getCheckedRadioButtonId());
        String tag=radioButton.getTag().toString();
        TerminalSendManager.getInstance().sendFcxMs(1,Integer.parseInt(tag));
        toast("已设置！");

    }
    @Click
    void headLeft(){
        finish();
    }
    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 1)
    public void eventBus(DmSxxInfo dmSxxInfo) {
        if(dmSxxInfo!=null){
            if("0".equals(dmSxxInfo.mode)){
                normalModeRb.setChecked(true);
            }else if("1".equals(dmSxxInfo.mode)){
                sosRb.setChecked(true);
            }else if("2".equals(dmSxxInfo.mode)){
                trackingModeRb.setChecked(true);
            }
        }
        hideLoading();
    }

}
